<?php
namespace RoleUser;
use Zend\ModuleManager\Feature\ServiceProviderInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\EventManager\EventInterface;


class Module implements AutoloaderProviderInterface , ConfigProviderInterface , ServiceProviderInterface
{

    public function onBootstrap(EventInterface $e)
    {
        $app = $e->getTarget();
        $eventManager = $e->getTarget()->getEventManager();
        $serviceManager = $app->getServiceManager();
        $sendListener = $serviceManager->get('upload_file_user_service_factory');
        $eventManager->attach($sendListener);
        
    }

    public function getConfig()
    {
        return include __DIR__ . '/config/module.config.php';
    }

    public function getControllerPluginConfig()
    {
        return array(
            'factories' => array(
                //'RoleUser' => 'RoleUser\Factory\Controller\Plugin\RoleUser',
            ),
        );
    }

    public function getAutoloaderConfig()
    {
        return array(
            'Zend\Loader\StandardAutoloader' => array(
                'namespaces' => array(
                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                ),
            ),
        );
    }

    public function getServiceConfig()
    {
        return array(
            'invokables' => array(
                'user_service' => 'RoleUser\Service\RoleUser',
                'admin_user_service' => 'RoleUser\Service\RoleAdminUser',
            ),
            'factories' => array(
                'user_role_mapper' => function($sm){
                    $options = $sm->get('user_module_options');
                    $config = $sm->get('config');
                    $mapper = new Mapper\RoleMapper($config);
                    $mapper->setDbAdapter($sm->get('user_zend_db_adapter'));
                    $entityClass = $options->getUserEntityClass();
                    $mapper->setEntityPrototype(new $entityClass);
                    //$mapper->setHydrator(new \ZfcUser\Mapper\UserHydrator(true));
                    return $mapper;
                },
                'role_user_create_service_factory' => 'RoleUser\Factory\RoleUserCreateServiceFactory',
            ),
        );
    }
}
